package com.ultrapower.bean;

import com.ultrapower.util.BytesUtils;
import com.ultrapower.util.CommonUtils;
import com.ultrapower.util.HBaseTables;

/**
 * 
 * @author wangy
 *
 */
public class SqlMetaDataBean {
	private String agentId;
	private long startTime;

	private int sqlId;

	private String sql;

	public SqlMetaDataBean() {
	}

	public SqlMetaDataBean(String agentId, long startTime, int sqlId) {
		if (agentId == null) {
			throw new NullPointerException("agentId must not be null");
		}
		this.agentId = agentId;
		this.sqlId = sqlId;
		this.startTime = startTime;
	}

	@Override
	public String toString() {
		return "SqlMetaDataBean [agentId=" + agentId + ", startTime=" + startTime + ", sqlId=" + sqlId + ", sql=" + sql
				+ "]";
	}

	public void readRowKey(byte[] rowKey) {
		this.agentId = BytesUtils.safeTrim(BytesUtils.toString(rowKey, 0, HBaseTables.AGENT_NAME_MAX_LEN));
		this.startTime = CommonUtils.recoveryTimeMillis(readTime(rowKey));
		this.sqlId = readSqlId(rowKey);
	}
	public void setSql(String sql) {
        this.sql = sql;
    }
	private static long readTime(byte[] rowKey) {
		return BytesUtils.bytesToLong(rowKey, HBaseTables.AGENT_NAME_MAX_LEN);
	}

	private static int readSqlId(byte[] rowKey) {
		return BytesUtils.bytesToInt(rowKey, HBaseTables.AGENT_NAME_MAX_LEN + BytesUtils.LONG_BYTE_LENGTH);
	}

}
